/*
 * Copyright 2010 - 2011, The PLDesktop Development Team
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

#ifndef TAR_H
#define TAR_H

#include <pltypes.h>
using namespace std;
#include <stdio.h>
#include <lib/tarfile.h>
#include <lib/tarheaderustar.h>

/**
 * Class to manage the virtual tar archive with the startup plugins and configuration.
 */
class Tar {
public:
    /**
     * The format from the tar file.
     */
    enum TarFormat {
        /**
         * A base tar format.
         */
        TarFormatBase       = 0,
        /**
         * A format with UStar extension.
         */
        TarFormatUStar      = 1
    };
    /**
     * Constructor.
     *
     * @param archiveStart The start address of the archive.
     * @param archiveEnd The end address of the archive.
     */
    Tar(uint32_t archiveStart, uint32_t archiveEnd);
    /**
     * Get the fileinformation from the tar archive.
     *
     * @param filename The filename to get the information for.
     * @return The fileinformation.
     */
    TarFile *file(const char *filename);
private:
    void readFile(uint32_t archiveStart, uint32_t archiveEnd);
    TarFile *getDirectory(TarHeader *header);
    TarFile *getDirectory(TarHeaderUStar *header);
    const char *getFileName(TarHeader *header);
    const char *getFileName(TarHeaderUStar *header);
    Tar::TarFormat m_format;
    PLRadixTree<TarFile *> *m_rootNode;
};

#endif
